<?php

namespace App\Observers;

use App\Jobs\TranslateSlug;
use App\Models\Topic;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Mews\Purifier\Facades\Purifier;

class TopicObserver
{
    //
    public function saving(Topic $topic)
    {
        $topic->content = clean($topic->content,'my_editor');
        $topic->desc = make_desc($topic->content);
    }

    public function saved(Topic $topic)
    {
        if(!$topic->slug){
            dispatch(new TranslateSlug($topic));
        }
    }


    public function updated(Topic $topic)
    {
        dispatch(new TranslateSlug($topic));
    }


    public function deleted(Topic $topic)
    {
        DB::table('replies')->where('topic_id',$topic->id)->delete();
    }
}
